home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / DVIEW000.LZH / KEYBOARD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-10  |  3.1 KB  |  162 lines

  1. /********************************************************************
  2.  FILENAME: KEYBOARD.CPP
  3.  AUTHOR  : JAKE HILL
  4.  DATE    : 12/1/94
  5.  
  6. ********************************************************************/
  7.  
  8. #ifdef __GNUC__
  9. #include <osbind.h>
  10. #else
  11. #include <tos.h>
  12. #endif
  13.  
  14. #include <stdio.h>
  15.  
  16. #include "keyboard.h"
  17.  
  18. extern void GetView(short *, short *, short *, unsigned short *);
  19.  
  20. extern short width;
  21. extern short height;
  22. extern short scale;
  23.  
  24. extern short flooropt;
  25. extern short floorcol;
  26. extern short nofloor;
  27. extern short wallopt;
  28. extern short wallcol;
  29. extern short singlestep;
  30. extern short draw_2D;
  31. extern short tellsect;
  32. extern short chksect;
  33.  
  34. void NewInterrupt(void)
  35. {
  36. #if 0
  37.    key_flags |= FLAG_UP;
  38. #endif
  39. }
  40.  
  41. void get_key(short *key, short *key_flags)
  42. {
  43.    char c;
  44.    short x, y, h, a;
  45.  
  46. #if 1
  47.    if (Cconis())
  48.       c = Cnecin();
  49.    else {
  50.       *key = -1;
  51.       return;
  52.    }
  53. #endif
  54.  
  55. #if 0
  56.    c = (char)Cnecin();
  57. #endif
  58.  
  59.    *key_flags = 0;
  60.    *key = 0;
  61.  
  62.    switch(c) {
  63.       case '8':      *key_flags |= FLAG_UP;
  64.                      break;
  65.  
  66.       case '2':      *key_flags |= FLAG_DOWN;
  67.                      break;
  68.  
  69.       case '4':      *key_flags |= FLAG_LEFT;
  70.                      break;
  71.  
  72.       case '6':      *key_flags |= FLAG_RIGHT;
  73.                      break;
  74.  
  75.       case '1':      *key_flags |= FLAG_SLEFT;
  76.                      break;
  77.  
  78.       case '3':      *key_flags |= FLAG_SRIGHT;
  79.                      break;
  80.  
  81.       case '-':      *key = KEY_MINUS;
  82.                      break;
  83.  
  84.       case '+':      *key = KEY_PLUS;
  85.                      break;
  86.       case 27:
  87.       case 'q':
  88.       case 'Q':      *key = 1;
  89.                      break;
  90.  
  91.       case 'f':      floorcol ^= 1;
  92.                      break;
  93.  
  94.       case 'F':      flooropt ^= 1;
  95.                      break;
  96.  
  97.       case 'n':      nofloor ^= 1;
  98.                      break;
  99.  
  100.       case 'w':      wallcol ^= 1;
  101.                      break;
  102.  
  103.       case 'W':      wallopt ^= 1;
  104.                      break;
  105.  
  106.       case 's':      singlestep ^= 1;
  107.                      break;
  108.  
  109.       case 'l':      draw_2D ^= 1;
  110.                           break;
  111.  
  112.       case 'c':      chksect ^= 1;
  113.                           break;
  114.  
  115.       case 't':      tellsect ^= 1;
  116.                           break;
  117.  
  118.       case '[':      width -= 10;
  119.                      break;
  120.  
  121.       case ']':      width += 10;
  122.                      break;
  123.  
  124.       case '{':      height -= 10;
  125.                      break;
  126.  
  127.       case '}':      height += 10;
  128.                      break;
  129.  
  130.       case '(':      scale -= 1;
  131.                      break;
  132.  
  133.       case ')':      scale += 1;
  134.                      break;
  135.  
  136.       case 'p':      GetView(&x, &y, &h, &a);
  137.                      printf("(%d,%d) %d %d\n", x, y, h, a);
  138.                      break;
  139.    }
  140. #if 0
  141.    printf("Key:%d  Key_flags: %d\n", *key, *key_flags);
  142. #endif
  143. }
  144.  
  145. void ResetKeyboardInt(void)
  146. {
  147. #if 0
  148.     if ( key_init )
  149.         _dos_setvect(9, OldInterrupt);
  150. #endif
  151. }
  152.  
  153. void SetKeyboardInt(void)
  154. {
  155. #if 0
  156.     atexit( ResetKeyboardInt );
  157.     OldInterrupt = _dos_getvect(9);
  158.     _dos_setvect(9, NewInterrupt);
  159.     key_init = 1;
  160. #endif
  161. }
  162.